package com.crm.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.crm.model.pojo.Competitor;
import com.crm.model.pojo.QuotationDetail;
import com.crm.model.pojo.QuotationRecord;
import com.crm.services.CustomerServices;
import com.crm.services.DictionaryServices;
import com.crm.services.OrderitemsServices;
import com.crm.services.QuotationDetailServices;
import com.crm.services.QuotationRecordService;
import com.crm.services.SaleTrackingLogServices;
import com.crm.services.SalesOpportunityServices;
import com.crm.services.UserServices;

@Controller
@RequestMapping("/sales")
public class QuotationDetailController {

	@Autowired
	private SalesOpportunityServices ss;
	@Autowired
	private DictionaryServices ds;
	@Autowired
	private CustomerServices cs;
	@Autowired
	private UserServices us;
	@Autowired
	private QuotationDetailServices qds;
	@Autowired
	private QuotationRecordService qrs;
	@Autowired
	OrderitemsServices orderitemsService;

	/**
	 * 报价记录初始页
	 * @return
	 */
	@RequestMapping("/quotationDetail")
	public ModelAndView findAllquotationRecord(Integer id) {
		String[] DId=new String[] {"全部数据"};
		JSONArray array=qds.ListTransJSONArray(id);//分页查询所有	
		ModelAndView mv=new ModelAndView("sales/quotationDetail");	
		List<Map<String, String>> productAllPage = orderitemsService.productAllPage();
		String json = JSONObject.toJSONString(productAllPage);
		mv.addObject("salesOpp",array);
		mv.addObject("proAll", json);
		mv.addObject("id", id);
		System.out.println("报价单明细");
		return mv;
	}
	
	/**
	 * 显示报价单明细
	 * @param id
	 * @return
	 */
	@RequestMapping("/showQuotationDetail")
	@ResponseBody
	public JSONArray findByquotationRecord(Integer id) {
		System.out.println("显示报价单明细");		
		JSONArray array=qds.ListTransJSONArray(id);//分页查询所有	
		return array;
	}
	/**
	 *新增 报价单
	 * @return
	 */
	@PostMapping("/AddquotationDetail")
	@ResponseBody
	public int Addsale(@RequestParam("notes") Object notes,@RequestParam("id") Integer id) {	
		System.out.println("d:"+notes);
		String str= String.valueOf(notes);	
		System.out.println(str);
		List<Map<String,String>> limap=JSONArray.parseObject(str,List.class);
		System.out.println("id:"+id);	
		qds.save(limap, id);
		return 1;			
	}
	
}
